<?php
require_once 'init.php';

if( isset($_REQUEST['mode']) )
{
	$mode = $_REQUEST['mode'];
	
	switch( $mode )
	{
		case 'systems':
			$prefixSql = '';
			$params = array();
			if( isset($_REQUEST['prefix']) )
			{
				$prefixSql = ' WHERE solarSystemName LIKE ?';
				$params[] = $_REQUEST['prefix'] . '%';
			}
			outputQuery("SELECT constellationID, solarSystemID, solarSystemName, security FROM mapSolarSystems" . $prefixSql, $params);
			break;

		case 'constellations':
			outputQuery("SELECT regionID, constellationID, constellationName FROM mapConstellations");
			break;

		case 'regions':
			outputQuery("SELECT regionID, regionName FROM mapRegions");
			break;
			
		case 'moons':
			$prefixSql = '';
			$params = array();
			if( isset($_REQUEST['prefix']) )
			{
				$prefixSql .= ' AND itemName LIKE ?';
				$params[] = $_REQUEST['prefix'] . '%';
			}
			if( isset($_REQUEST['region']) )
			{
				$prefixSql .= ' AND regionID = ?';
				$params[] = $_REQUEST['region'];
			}
			outputQuery("SELECT itemID, itemName, solarSystemID FROM mapDenormalize WHERE groupID = 8" . $prefixSql, $params);
			break;
	}
}